home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 699 / iffconvert / src / iffconvert.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  8KB  |  289 lines

  1. /*************************************************************************
  2. *                                                                        *
  3. *   IFFCONVERT.C                       Modified: 26.5.92                 *
  4. *                                                                        *
  5. *   Tool to convert various IFF-ILBM formats using the iffpack routines  *
  6. *                                                                        *
  7. *   cc iffconvert.c                                                      *
  8. *                                                                        *
  9. *   ln iffconvert.o filereq.o iffpack.o reqtoolsglue.o                   *
  10. *                                                                        *
  11. *   V1.0                                                                 *
  12. *                                                                        *
  13. *   V1.1   reqtools Filerequester                                        *
  14. *          Topaz 8 fest eingebaut, sonst Probleme mit anderen Fonts      *
  15. *                                                                        *
  16. *   V1.11  Bug mit übergroßen Windows entfernt, nur noch Englische Vers. *
  17. *                                                                        *
  18. **************************************************************************/
  19.  
  20. #include <intuition/intuition.h>
  21. #include <exec/memory.h>
  22. #include <functions.h>
  23. #include <stdio.h>
  24.  
  25. #define LOAD   0
  26. #define SAVE   1
  27. #define DELETE 2
  28.  
  29. #include "iffmenu.h"
  30.  
  31. #include "iffpack.h"
  32.  
  33. struct NewScreen ns;
  34. struct NewWindow nw;
  35.  
  36. ULONG ReqToolsBase;
  37.  
  38. struct IntuitionBase *IntuitionBase=NULL;
  39. struct GfxBase *GfxBase=NULL;
  40. ULONG File;
  41.  
  42. struct Screen *s=NULL;
  43. struct Window *w=NULL;
  44.  
  45. struct TextAttr txtattr= {
  46.    (STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT};
  47.  
  48. FILE *fp=NULL;
  49.  
  50. char *FileRequest();
  51.  
  52. long selected=0;
  53.  
  54. main()
  55. {
  56.    long view;
  57.    short mode=0;
  58.    int err;
  59.    char *name;
  60.    struct IntuiMessage *msg;
  61.    USHORT num;
  62.  
  63.    short ende=0;
  64.  
  65.    new_window.FirstGadget=NULL;
  66.  
  67.    if(!(IntuitionBase = (struct IntuitionBase *)
  68.          OpenLibrary("intuition.library",0L))) quit("No intuition-library");
  69.  
  70.    if(!(GfxBase = (struct GfxBase *)
  71.          OpenLibrary("graphics.library",0L))) quit("No graphics-library");
  72.  
  73.    if(!(ReqToolsBase=(ULONG)OpenLibrary("reqtools.library",37L)))
  74.       quit("No reqtools-library V37");
  75.  
  76.    if(InitRequest())
  77.       quit("No Memory");
  78.  
  79.    OpenDefaultScreen();
  80.    PrintIText(w->RPort,FIRSTTEXT,0L,0L);
  81.  
  82.    while(!ende) {
  83.       Wait(1L<<w->UserPort->mp_SigBit);
  84.       while(msg=(struct IntuiMessage *)GetMsg(w->UserPort)) {
  85.          if(msg->Class==MENUPICK) {
  86.             num=msg->Code;
  87.             while(num!=MENUNULL) {
  88.                if(MENUNUM(num)==0){
  89.                   switch(ITEMNUM(num)) {
  90.                      case 0:  if(name=FileRequest(w,LOAD)) {
  91.                                  if(fp=fopen(name,"r")) {
  92.                                     LoadScreen(fp);
  93.                                     fclose(fp);
  94.                                     fp=NULL;
  95.                                  }  else DisplayBeep(s);
  96.                               }
  97.                               break;
  98.                      case 1:  if(name=FileRequest(w,SAVE)) {
  99.                                  if(fp=fopen(name,"w")) {
  100.                                     SetWait(w);
  101.                                     switch(SUBNUM(num)) {
  102.                                        case 0:  err=WriteWindow(fp,w,0);
  103.                                                 if(err) SetAlert(errortext[err]);
  104.                                                 break;
  105.                                        case 1:  err=WriteWindow(fp,w,1);
  106.                                                 if(err) SetAlert(errortext[err]);
  107.                                                 break;
  108.                                        case 2:  err=WriteWindow(fp,w,2);
  109.                                                 if(err) SetAlert(errortext[err]);
  110.                                                 break;
  111.                                     }
  112.                                     ClearWait(w);
  113.                                     fclose(fp);
  114.                                     fp=NULL;
  115.                                     if(err) unlink(name);
  116.                                  } else SetAlert("Cannot open file");
  117.                               }
  118.                               break;
  119.                      case 2:  if(name=FileRequest(w,DELETE)) {
  120.                                  unlink(name);
  121.                               }
  122.                               break;
  123.                      case 3:  break;
  124.                      case 4:  selected=ItemAddress(FIRSTMENU,(long)num)
  125.                                           ->Flags&CHECKED;
  126.                               ShowTitle(s,selected);
  127.                               break;
  128.                      case 5:  break;
  129.                      case 6:  ende=1;
  130.                               break;
  131.                   }
  132.                }
  133.                num=ItemAddress(FIRSTMENU,(long)num)->NextSelect;
  134.             }
  135.          }
  136.       }
  137.    }
  138.    quit(NULL);
  139. }
  140. _abort()
  141. {
  142.    quit(NULL);
  143. }
  144. quit(err)
  145. char *err;
  146. {
  147.    if(err) SetAlert(err);
  148.    IFFCleanup();
  149.    ClearWait(NULL);
  150.    if(fp) fclose(fp);
  151.    if(w) CloseWindow(w);
  152.    if(s) CloseScreen(s);
  153.    FreeRequest();
  154.    if(ReqToolsBase) CloseLibrary(ReqToolsBase);
  155.    if(GfxBase) CloseLibrary(GfxBase);
  156.    if(IntuitionBase) CloseLibrary(IntuitionBase);
  157.    exit(0);
  158. }
  159.  
  160. SetAlert(err)
  161. char *err;
  162. {
  163.    char buffer[40];
  164.    short len;
  165.    buffer[0]=0;
  166.    if(!IntuitionBase) return(); /* Kein Alert möglich */
  167.    strcpy(&buffer[1],"\240\30");
  168.    strcpy(&buffer[3],err);
  169.    len=strlen(err);
  170.    /* 2 Null-Bytes als Abschluß */
  171.    buffer[len+3+1]=0;
  172.    buffer[len+3+2]=0;
  173.    DisplayAlert(RECOVERY_ALERT,buffer,40L);
  174. }
  175.  
  176. OpenDefaultScreen()
  177. {
  178.    if(w) {
  179.       ClearMenuStrip(w);
  180.       CloseWindow(w);
  181.    }
  182.    w=NULL;
  183.    if(s) CloseScreen(s);
  184.    s=NULL;
  185.    nw=new_window;
  186.    ns=NewScreen;
  187.    ns.Font=&txtattr;
  188.    if(!(s=OpenScreen(&ns)))
  189.       quit("FATAL ERROR: Cannot open default Screen");
  190.    nw.Screen=s;
  191.    if(!(w=OpenWindow(&nw)))
  192.    quit("FATAL ERROR: Cannot open default Window");
  193.    SetMenuStrip(w,FIRSTMENU);
  194.    ShowTitle(s,(long)selected);
  195. }
  196. LoadScreen(fp)
  197. FILE *fp;
  198. {
  199.    int err;
  200.  
  201.    ns=NewScreen;
  202.    nw=new_window;
  203.  
  204.    SetWait(w);
  205.    if(err=ReadPicSize(fp,&nw.Width,&nw.Height,
  206.                          &ns.Width,&ns.Height,&ns.Depth,&ns.ViewModes)) {
  207.       SetAlert(errortext[err]);
  208.       ClearWait(w);
  209.       return();
  210.    }
  211.    ClearWait(w);
  212.  
  213.    if(ns.Width<320) ns.Width=320;
  214.    if(ns.Height<200) ns.Height=200;
  215.    if(ns.Width<nw.Width) ns.Width=nw.Width;
  216.    if(ns.Height<nw.Height) ns.Height=nw.Height;
  217.  
  218.    ClearMenuStrip(w);
  219.    CloseWindow(w);
  220.    w=NULL;
  221.    CloseScreen(s);
  222.    s=NULL;
  223.    if(!(s=OpenScreen(&ns))) {
  224.       SetAlert("Cannot open screen");
  225.       OpenDefaultScreen();
  226.       return();
  227.    }
  228.    nw.Screen=s;
  229.  
  230.    if(!(w=OpenWindow(&nw))) {
  231.       SetAlert("Cannot open window");
  232.       OpenDefaultScreen();
  233.       return();
  234.    }
  235.  
  236.    SetMenuStrip(w,FIRSTMENU);
  237.    ShowTitle(s,(long)selected);
  238.    SetColors(&s->ViewPort);
  239.  
  240.    SetWait(w);
  241.    if(err=ReadBody(w->RPort,fp))
  242.         SetAlert(errortext[err]);
  243.  
  244.    ClearWait(w);
  245.    fclose(fp);fp=NULL;
  246. }
  247.  
  248. USHORT Pointer[]= {
  249.    0x0000,0x0000,
  250.    0x0f80,0x0d80,
  251.    0x1040,0x1040,
  252.    0x2220,0x2020,
  253.    0x4210,0x4010,
  254.    0x8208,0x8008,
  255.    0x8208,0x8008,
  256.    0x8388,0x0000,
  257.    0x8008,0x8008,
  258.    0x8008,0x8008,
  259.    0x4010,0x4010,
  260.    0x2020,0x2020,
  261.    0x1040,0x1040,
  262.    0x0f80,0x0D80,
  263.    0x0000,0x0000
  264.    };
  265.  
  266. #define POINTERMEM (15L*4L)
  267. static USHORT *chipmem=0;
  268.  
  269. SetWait(w)
  270. struct Window *w;
  271. {
  272.    short a;
  273.    ClearWait(w);
  274.    if(chipmem=AllocMem(POINTERMEM,MEMF_CHIP)) {
  275.       for(a=0;a<30;a++) chipmem[a]=Pointer[a];
  276.       SetPointer(w,chipmem,13L,16L,-6L,-6L);
  277.    }
  278. }
  279. ClearWait(w)
  280. struct Window *w;
  281. {
  282.    if(w) ClearPointer(w);
  283.    if(chipmem) FreeMem(chipmem,POINTERMEM);
  284.    chipmem=0;
  285. }
  286.  
  287.  
  288.  
  289.